import os
import logging
from logging.handlers import TimedRotatingFileHandler

#日志目录
LOG_DIR = '/Users/aiqikeji/Documents/workspace_python/run_log/learn_python_test'
# 日志文件名
LOG_FILE_NAME = LOG_DIR + '/log.log'

# 检查log目录是否存在
if (not os.path.exists(LOG_DIR)):
	os.mkdir(LOG_DIR)

# 日志输出
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
# 控制台输出
console_handler = logging.StreamHandler()
logger.addHandler(console_handler)
# 按时间分割文件
formatter = logging.Formatter("%(asctime)s - %(levelname)s : %(message)s")
log_file_handler = TimedRotatingFileHandler(filename=LOG_FILE_NAME, when="D", interval=1, backupCount=7)
log_file_handler.setFormatter(formatter)
log_file_handler.setLevel(logging.INFO)
logger.addHandler(log_file_handler)


class LogUtil:
	@classmethod
	def info(cls, msg):
		logger.info(msg)

	@staticmethod
	def error(msg):
		logger.error(msg)